// pages/search/search.js
Page({

      /**
       * 页面的初始数据
       */
      data: {
            focus:true,
            functionList:[

            ],
            noticeList:[],
            allFunction:[
                  {
                        icon:'icon-kuaidi',
                        title:'快递上门',
                        to:'/pages/express/express',
                        like:'快递上门'
                  },
                  {
                        icon:'icon-huzhu',
                        title:'邻里互助',
                        to:'/pages/helpEach/helpEach',
                        like:'邻居互助邻里互助'
                  },
                  {
                        icon:'icon-add',
                        title:'发布邻里互助',
                        to:'/pages/publishHelp/publishHelp',
                        like:'邻居互助邻里互助发布'
                  },
                  {
                        icon:'icon-yao',
                        title:'访客邀请',
                        to:'/pages/yao/yao',
                        like:'访客邀请邀请访客'
                  },
                  {
                        icon:'icon-yaoqingliebiao',
                        title:'邀请卡列表',
                        to:'/pages/yaoList/yaoList',
                        like:'邀请卡列表邀请列表'
                  },
                  {
                        icon:'icon-kuaidiyuan-xianxing',
                        title:'快递上门订单',
                        to:'/pages/expressOrder/expressOrder',
                        like:'快递上门订单快递订单'
                  },
                  {
                        icon:'icon-shenghuo-copy',
                        title:'生活服务',
                        to:'/pages/lifeService/lifeService',
                        like:'生活服务日常服务'
                  },
                  {
                        icon:'icon-yaoqingliebiao',
                        title:'完善信息',
                        to:'/pages/userInfo/userInfo',
                        like:'完善信息个人信息'
                  },
                  {
                        icon:'icon-weixiuguanli',
                        title:'故障报修',
                        to:'/pages/repair/repair',
                        like:'故障报修故障维修物业报修故障保修'
                  },
                  {
                        icon:'icon-qinyoujiankang',
                        title:'我的亲友',
                        to:'/pages/kin/kin',
                        like:'我的亲友我的联系人添加联系人添加亲友'
                  },
                  {
                        icon:'icon-lajifenlei',
                        title:'垃圾分类',
                        to:'/pages/garbageSorting/garbageSorting',
                        like:'垃圾分类垃圾查询垃圾'
                  },
                  {
                        icon:'icon-cheweigongxiang',
                        title:'车位共享',
                        to:'/pages/driveway/driveway',
                        like:'车位共享车位'
                  },
                  {
                        icon:'icon-gonggao',
                        title:'每日新闻',
                        to:'/pages/news/news',
                        like:'每日新闻每天新闻查看新闻'
                  },
                  {
                        icon:'icon-gonggao',
                        title:'社区公告',
                        to:'/pages/noticeList/noticeList',
                        like:'社区公告'
                  },
            ],
            val:''
      },
      submitSearch(e){
            this.submit(e.detail.value);
      },
      submit(e){
            let keyword=e;
            if(keyword==''){
                  this.setData({
                        functionList:[],
                        noticeList:[]
                  })
                  return;
            }
            // 搜索公告
            wx.request({
                  url:getApp().globalData.host+'client/notice/listByName?title='+keyword,
                  success:res=>{
                        this.setData({
                              noticeList:res.data.data.noticeList
                        })
                  },
                  fail:()=>{
                        wx.showToast({
                              title: '服务器繁忙',
                              icon:'error'
                        })
                  }
            })

            // 搜索功能
            let arr=[];
            let i=0;
            this.data.allFunction.forEach(item=>{
                  i=item.like.indexOf(keyword);
                  if(i!=-1){
                        arr.push(item);
                  }
            })
            this.setData({
                  functionList:arr
            })
      },

      /**
       * 生命周期函数--监听页面加载
       */
      onLoad: function (options) {
            let val=options.val;
            if(val!=undefined){
                  val=val.replace('。','');
                  this.setData({
                        val:val
                  })
                  this.submit(val);
            }

      },

      /**
       * 生命周期函数--监听页面显示
       */
      onShow: function () {

      },


})